package com.metaera.app.ui.fragments;

import android.os.Bundle;
import android.view.View;

import com.lxj.xpopup.XPopup;
import com.metaera.app.R;
import com.metaera.app.controller.presenter.CalendarPresenter;
import com.metaera.app.controller.presenter.CategoryPresenter;
import com.metaera.app.controller.view.CalendarCategoryView;
import com.metaera.app.ui.popup.CalendarPopup;
import com.metaera.app.ui.core.BaseFragment;

import net.lucode.hackware.magicindicator.MagicIndicator;

import androidx.viewpager.widget.ViewPager;

public class FlashNewsCalendarTypeFragment extends BaseFragment {

    @Override
    protected int getLayoutId() {

        return R.layout.fragment_flash_news_calendar_type;
    }

    @Override
    protected void initialize(Bundle savedInstanceState) {
        // find
        ViewPager viewPager = findViewById(R.id.view_pager);
        View imageViewCalendar = findViewById(R.id.image_view_calendar);
        MagicIndicator magicIndicator = findViewById(R.id.magic_indicator);

        // init TODO: 这个放后面处理
        viewPager.setOffscreenPageLimit(3);

        // 分类
        CategoryPresenter categoryPresenter = new CategoryPresenter();
        CalendarCategoryView categoryView = new CalendarCategoryView(getChildFragmentManager(), viewPager, magicIndicator);
        categoryPresenter.setModelAndView(categoryView);
        categoryPresenter.calendar();

        // 日历
        CalendarPresenter presenter = new CalendarPresenter();
        CalendarPopup calendarPopup = new CalendarPopup(
                this,
                presenter,
                categoryView.getItem(viewPager.getCurrentItem()).getId()
        );
        presenter.setModelAndView(calendarPopup);

        // 监听
        imageViewCalendar.setOnClickListener(v -> {
            calendarPopup.setCategoryID(categoryView.getItem(viewPager.getCurrentItem()).getId());
            new XPopup.Builder(getContext())
                    .isLightStatusBar(true)
                    .atView(imageViewCalendar)
                    .asCustom(calendarPopup)
                    .show();
        });
    }

}
